﻿<?php

class WController extends Controller
{
	public function actionIndex()
	{
		if(Yii::app()->request->isAjaxRequest){
			$content = $_POST['blog'];
			$imageUrl = $_POST['imgUrl'];
			$sortId = $_POST['sortId'];
			$title = $_POST['title'];
			$brief = substr(rtrim(strip_tags($content)),0,50);

			$article_list = new ArticleList;
			$article_list->article_title = $title;
			$article_list->article_brief = $brief;
			$article_list->article_createtime = date('Y-m-d');
			$article_list->article_image_url = $imageUrl;
			$article_list->article_content = $content;
			$article_list->article_sort_id = $sortId;
			if($article_list->save())
			{
				echo "success";
			}else{
				echo "error";
			}
		}
		$this->render('index');
	}

	public function actionCreateSort()
	{
		if(Yii::app()->request->isAjaxRequest){
			$sort = $_POST['articleSort'];
			$article_sort = new articleSort;
			$article_sort->sort_name = $sort;
			$article_sort->sort_createtime = date('Y-m-d');
			$article_sort->save();
			echo true;
		}
	}

	public function actionSelectTag()
	{
		if(Yii::app()->request->isAjaxRequest)
		{
			//$selectTag = new article_sort;
			$Tag=ArticleSort::model()->findAll(array(
				'select'=>'article_sort_id,sort_name',
				//'condition'=>'1 limit 3',
			));
			echo CJSON::encode($Tag);
		}
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}